﻿using MediatR;
using Traceability.App.Apilication.Common.Health;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App.Apilication.Handler.Health
{
    public class GetHealthHandler : IRequestHandler<GetHealthCommon, ApiResult<List<HealthModel>>>
    {
        private readonly IBaseRespository<HealthModel> healthRepo;

        public GetHealthHandler(IBaseRespository<HealthModel> healthRepo)
        {
            this.healthRepo = healthRepo;
        }


        public Task<ApiResult<List<HealthModel>>> Handle(GetHealthCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<HealthModel>> res = new ApiResult<List<HealthModel>>();

            var info = healthRepo.GetAll().Where(x=>x.Production_Batch==request.Production_Batch&&x.Delete_Identifier==false).ToList();
            res.Code = ApiEnum.Success;
            res.Message = "保健信息展示";
            res.Data = info;
            return Task.FromResult(res);

        }
    }
}
